//index.js
//获取应用实例
const app = getApp()
const mineService = require('../../service/mine.js');

Page({
  data: {
    title:"提现",
    loading:false,
    balance:0.00,
    disabled:false,
    money:""
  },
  onLoad: function (options) {
    this.setData({
      balance: options.balance
    })
  },
  formSubmit(e){
    console.log(e);
    let d = {
      ...e.detail.value,
      unionId: app.globalData.userinfo.unionId
    }
    console.log("----------" + e.detail.value["price"]);
    if (e.detail.value["alipay"] == "" || e.detail.value["alipay"] == null) {
      wx.showModal({
        title: '提醒',
        content: '请输入提现账户！',
        showCancel: false,
        confirmText: "确定",
        success: (res) => {
        }
      })
    } else if (e.detail.value["price"] < 1){
      wx.showModal({
        title: '提醒',
        content: '请输入提现金额!',
        showCancel: false,
        confirmText: "确定",
        success: (res) => {
        }
      })
    } else if (e.detail.value["price"] > this.data.balance){
      wx.showModal({
        title: '提醒',
        content: '提现金额不能大于可用余额!',
        showCancel: false,
        confirmText: "确定",
        success: (res) => {
        }
      })
    }
    else if (e.detail.value["price"] < 100) {
      wx.showModal({
        title: '提醒',
        content: '提现金额必须大于100!',
        showCancel: false,
        confirmText: "确定",
        success: (res) => {
        }
      })
    }else {
      this.setData({
        loading: true
      })
      mineService.accountCash(d).then(res => {
        this.setData({
          loading: false
        })
        if (res.resCode == 0) {
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 2000
          });
          wx.navigateBack({
            delta: 1
          })
        }
      }, () => {
        this.setData({
          loading: false
        })
      })
    }
    
  },
  formReset(){},
  setAll(){
    this.setData({
      money:this.data.balance
    })
  }
})
